﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web;
using System.Data;
using System.Configuration;




public partial class admin_NewClientRent : System.Web.UI.Page
{
    string c_id = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["email"] == null)
        {
            Response.Redirect("sessiont.aspx");
        }
        Label2.Text = Session["email"].ToString();

    }
    //[WebMethod]

    //public static string InsertMethod(string f_name, string m_name, string l_name, string d_o_b, string occu, string h_no, string city, string street, string ssn, string zip_code, string country, string email, string ph_no, string cat, string c_cat, string cat1)
    //{
     
       
    //        SqlConnection conn = null;
    //        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
    //        {

    //            SqlCommand cmd = new SqlCommand("Insert into client_add1 values('" + f_name + "', '" + m_name + "', '" + l_name + "','" + d_o_b + "','" + occu + "','" + h_no + "','" + city + "','" + street + "','" + ssn + "','" + zip_code + "','" + country + "','" + email + "','" + ph_no + "','" + cat + "','" + c_cat + "','" + cat1 + "')", conn);
    //            {
    //                conn.Open();
    //                cmd.ExecuteNonQuery();
    //                return "True";
    //            }
    //        }
    //    }
    

    
    protected void Cancel_Click(object sender, System.EventArgs e)
    {
        //btnSave_Student.Visible = true;
    }



  
    protected void Save_Click(object sender, System.EventArgs e)
    {

        string cat = null;
        cat = DropDownList1.SelectedValue;
        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();
        SqlCommand scmd = new SqlCommand("SELECT * FROM client_add_rent where email_id='" + txtemail.Text + "'", conn);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {

            Label1.Visible = true;


        }


        else
        {
            dr.Close();


            //SqlConnection conn = null;

            //conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);



            if (cat.Equals("Yes"))
            {

                Random r1 = new Random();
                int num = r1.Next(0, 99999999); // generate random number
                string number = string.Format("{0:D8}", num);

                Random r2 = new Random();
                int num2 = r2.Next(0, 26); // generate random letter
                char letter = (char)('A' + num2);


                c_id = letter + number; // join both as ID 


                SqlCommand cmd = new SqlCommand("Insert into client_add_rent values(@c_id,@type,@wants_to,@property,@agent_name,@client_fullname,@property_type,@house_no,@city,@street,@ssn,@zip,@country,@email_id,@phone,@room_no,@floor,@ac,@parking,@elevator,@price,@prop_size,@adding_by,@size_no,@entry_date,@roommates,@no_roommates,@gaurantee,@voucher,@smoke,@animal,@prop_cond,@balcony,@available,@comments,@choose_cat,@c_cat,@category,@safe_room ,@status)", conn);
                cmd.Parameters.AddWithValue("@c_id", c_id);
                cmd.Parameters.AddWithValue("@type", DropDownList5 .SelectedValue );
                cmd.Parameters.AddWithValue("@wants_to", "Rent");
                cmd.Parameters.AddWithValue("@property", DropDownList6.SelectedValue);
                
                cmd.Parameters.AddWithValue("@agent_name", DropDownList15.SelectedValue);
                cmd.Parameters.AddWithValue("@client_fullname", txtmname .Text );
                cmd.Parameters.AddWithValue("@property_type", txtname1.Text );
                cmd.Parameters.AddWithValue("@house_no", txthno .Text );
                cmd.Parameters.AddWithValue("@city", txtcity.Text );
                cmd.Parameters.AddWithValue("@street", txtstreet.Text );
                cmd.Parameters.AddWithValue("@ssn", txtssn.Text );
                cmd.Parameters.AddWithValue("@zip", txtzip.Text );
                cmd.Parameters.AddWithValue("@country",txtcountry.Text );
                cmd.Parameters.AddWithValue("@email_id", txtemail.Text );
                cmd.Parameters.AddWithValue("@phone", txtphno.Text );
                cmd.Parameters.AddWithValue("@room_no", TextBox3.Text );
                cmd.Parameters.AddWithValue("@floor", TextBox4.Text );
                cmd.Parameters.AddWithValue("@ac", DropDownList16.Text );
                cmd.Parameters.AddWithValue("@parking", TextBox7.Text );
                cmd.Parameters.AddWithValue("@elevator", DropDownList17.SelectedValue );
                cmd.Parameters.AddWithValue("@price", TextBox9.Text );
                cmd.Parameters.AddWithValue("@prop_size",DropDownList7.Text );
                cmd.Parameters.AddWithValue("@adding_by", Session ["email"]);
                cmd.Parameters.AddWithValue("@size_no", TextBox11.Text );
                cmd.Parameters.AddWithValue("@entry_date", TextBox12.Text );
                cmd.Parameters.AddWithValue("@roommates", DropDownList8.SelectedValue );
                cmd.Parameters.AddWithValue("@no_roommates", TextBox14.Text );
                cmd.Parameters.AddWithValue("@gaurantee", DropDownList10.SelectedValue );
                cmd.Parameters.AddWithValue("@voucher", DropDownList9.SelectedValue );
                cmd.Parameters.AddWithValue("@smoke", DropDownList11.SelectedValue );
                cmd.Parameters.AddWithValue("@animal", DropDownList12.SelectedValue );
                cmd.Parameters.AddWithValue("@prop_cond", DropDownList13.SelectedValue );
                cmd.Parameters.AddWithValue("@balcony", DropDownList14.SelectedValue );
                
                cmd.Parameters.AddWithValue("@available", TextBox10.Text );
                cmd.Parameters.AddWithValue("@comments", TextBox13.Text );
                cmd.Parameters.AddWithValue("@choose_cat", ddlcategory.SelectedValue );
                cmd.Parameters.AddWithValue("@c_cat", DropDownList1.SelectedValue );
                cmd.Parameters.AddWithValue("@category", txtcatname.Text );
                cmd.Parameters.AddWithValue("@safe_room", TextBox5.Text );
                cmd.Parameters.AddWithValue("@status", "0");

                cmd.ExecuteNonQuery();
                SqlCommand cmd1 = new SqlCommand("Insert into client_add1 values(@c_id ,@f_name,@type_,@status1)", conn);
                cmd1.Parameters.AddWithValue("@c_id", c_id);
                cmd1.Parameters.AddWithValue("@f_name", txtmname.Text);
                cmd1.Parameters.AddWithValue("@type_", "Rent");

                cmd1.Parameters.AddWithValue("@status1", "0");
                cmd1.ExecuteNonQuery();
                Session["c_id"] = c_id;
                Response.Redirect("partner_client_add_confirmation.aspx?=" + c_id.Trim());

            }
            else
            {

                Random r1 = new Random();
                int num = r1.Next(0, 99999999); // generate random number
                string number = string.Format("{0:D8}", num);

                Random r2 = new Random();
                int num2 = r2.Next(0, 26); // generate random letter
                char letter = (char)('A' + num2);


                c_id = letter + number; // join both as ID 
                SqlCommand cmd = new SqlCommand("Insert into client_add_rent values(@c_id,@type,@wants_to,@property,@agent_name,@client_fullname,@property_type,@house_no,@city,@street,@ssn,@zip,@country,@email_id,@phone,@room_no,@floor,@ac,@parking,@elevator,@price,@prop_size,@adding_by,@size_no,@entry_date,@roommates,@no_roommates,@gaurantee,@voucher,@smoke,@animal,@prop_cond,@balcony,@available,@comments,@choose_cat,@c_cat,@category,@safe_room,@status )", conn);
                cmd.Parameters.AddWithValue("@c_id", c_id);
                cmd.Parameters.AddWithValue("@type", DropDownList5.SelectedValue);
                cmd.Parameters.AddWithValue("@wants_to","Rent");
                cmd.Parameters.AddWithValue("@property", DropDownList6.SelectedValue);
               
                cmd.Parameters.AddWithValue("@agent_name", DropDownList15.SelectedValue);
                cmd.Parameters.AddWithValue("@client_fullname", txtmname.Text);
                cmd.Parameters.AddWithValue("@property_type", txtname1.Text);
                cmd.Parameters.AddWithValue("@house_no", txthno.Text);
                cmd.Parameters.AddWithValue("@city", txtcity.Text);
                cmd.Parameters.AddWithValue("@street", txtstreet.Text);
                cmd.Parameters.AddWithValue("@ssn", txtssn.Text);
                cmd.Parameters.AddWithValue("@zip", txtzip.Text);
                cmd.Parameters.AddWithValue("@country", txtcountry.Text);
                cmd.Parameters.AddWithValue("@email_id", txtemail.Text);
                cmd.Parameters.AddWithValue("@phone", txtphno.Text);
                cmd.Parameters.AddWithValue("@room_no", TextBox3.Text);
                cmd.Parameters.AddWithValue("@floor", TextBox4.Text);
                cmd.Parameters.AddWithValue("@ac", DropDownList16.Text);
                cmd.Parameters.AddWithValue("@parking", TextBox7.Text);
                cmd.Parameters.AddWithValue("@elevator",  DropDownList17.SelectedValue );
                cmd.Parameters.AddWithValue("@price", TextBox9.Text);
                cmd.Parameters.AddWithValue("@prop_size", DropDownList7.Text);
                cmd.Parameters.AddWithValue("@adding_by", Session["email"]);
                cmd.Parameters.AddWithValue("@size_no", TextBox11.Text);
                cmd.Parameters.AddWithValue("@entry_date", TextBox12.Text);
                cmd.Parameters.AddWithValue("@roommates", DropDownList8.SelectedValue);
                cmd.Parameters.AddWithValue("@no_roommates", TextBox14.Text);
                cmd.Parameters.AddWithValue("@gaurantee", DropDownList10.SelectedValue);
                cmd.Parameters.AddWithValue("@voucher", DropDownList9.SelectedValue);
                cmd.Parameters.AddWithValue("@smoke", DropDownList11.SelectedValue);
                cmd.Parameters.AddWithValue("@animal", DropDownList12.SelectedValue);
                cmd.Parameters.AddWithValue("@prop_cond", DropDownList13.SelectedValue);
                cmd.Parameters.AddWithValue("@balcony", DropDownList14.SelectedValue);

                cmd.Parameters.AddWithValue("@available", TextBox10.Text);
                cmd.Parameters.AddWithValue("@comments", TextBox13.Text);
                cmd.Parameters.AddWithValue("@choose_cat", ddlcategory.SelectedValue);
                cmd.Parameters.AddWithValue("@c_cat", "0");
                cmd.Parameters.AddWithValue("@category", txtcatname.Text);
                cmd.Parameters.AddWithValue("@safe_room", TextBox5.Text);
                cmd.Parameters.AddWithValue("@status", "0");
                cmd.ExecuteNonQuery();

                SqlCommand cmd1 = new SqlCommand("Insert into client_add1 values(@c_id ,@f_name,@type_,@status1)", conn);
                cmd1.Parameters.AddWithValue("@c_id", c_id);
                cmd1.Parameters.AddWithValue("@f_name", txtmname.Text);
                cmd1.Parameters.AddWithValue("@type_", "Rent");

                cmd1.Parameters.AddWithValue("@status1", "0");
                cmd1.ExecuteNonQuery();
                Session["c_id"] = c_id;
                Response.Redirect("partner_client_add_confirmation.aspx?=" + c_id.Trim());

            }
        }
        conn.Close();


    }
    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
          Response.Redirect("../partner.aspx");
    }
}